package com.summer.shopping.controller;

import com.summer.shopping.domain.table.Banner;
import com.summer.shopping.domain.table.dto.BannerDto;
import com.summer.shopping.domain.table.dto.BannerQueryParam;
import com.summer.shopping.domain.table.dto.PageDTO;
import com.summer.shopping.domain.table.dto.ShoppingCarDTO;
import com.summer.shopping.domain.table.vo.BannerVo;
import com.summer.shopping.domain.table.vo.ShoppingCartVo;
import com.summer.shopping.service.BannerService;
import com.summer.shopping.utils.PageResult;
import com.summer.shopping.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("banner")
@Slf4j
public class BannerController {

    @Autowired
    BannerService bannerService;

    @PostMapping("add")
    public Result<String> add(@RequestBody BannerDto bannerDto){
        log.info("添加轮播图：{}",bannerDto);
        bannerService.add(bannerDto);
        return Result.ok("添加成功");
    }

    @GetMapping("list")
    public Result<PageResult<BannerVo>> list(PageDTO pageDTO, BannerQueryParam bannerQueryParam){
        log.info("查询轮播图:{}",pageDTO);
        PageResult<BannerVo> bannerVoPageResult=bannerService.getPageList(pageDTO,bannerQueryParam);
        return Result.ok(bannerVoPageResult);
    }

    @GetMapping("{id}")
    public Result<BannerVo> getOneById(@PathVariable Integer id){
        log.info("查询轮播图ByID:{}",id);
        BannerVo bannerVo=bannerService.getOneById(id);
        return Result.ok(bannerVo);
    }

    @DeleteMapping
    public Result<String> delete(@RequestParam List<Long> ids){
        log.info("批量删除轮播图:{}",ids);
        bannerService.delete(ids);
        return Result.ok("批量删除成功");
    }

    @PutMapping
    public Result<String> update(@RequestBody BannerDto bannerDto){
        log.info("修改轮播图:{}",bannerDto);
        bannerService.up(bannerDto);
        return Result.ok("修改成功");
    }
}
